package com.cn.shuangzi.ad;

import android.os.Bundle;

import com.cn.shuangzi.SZBaseActivity;
import com.cn.shuangzi.ad.manager.AdInterstitialFullManager;
import com.cn.shuangzi.ad.manager.SplashMinWindowManager;
import com.cn.shuangzi.ad.util.OnAdClosedListener;
import com.cn.shuangzi.ad.util.TTVideoInteractionAdLoader;
import com.cn.shuangzi.util.SZUtil;

/**
 * Created by CN.
 */
public abstract class ADBaseActivity extends SZBaseActivity {

    public boolean isShownInteractionAd = false;
    public boolean isStop = false;

    public void showInteractionAdGroMore(String unitId, Class<?> classVip) {
        showInteractionAdGroMore(unitId, classVip, true,null);
    }

    public void showInteractionAdGroMore(String unitId,String scenarioId, Class<?> classVip) {
        showInteractionAdGroMore(unitId,classVip,true,scenarioId);
    }
    public void showInteractionAdGroMore(String unitId, final Class<?> classVip, final boolean isOnceShowVip,String scenarioId) {
        try {
            if (isShowAd()) {
                if (!isStop && !isShownInteractionAd) {
                    if (ADManager.getInstance().isShowGroMoreInteractionAd(SplashMinWindowManager.getInstance().isSplashShown())) {
                        SZUtil.logError("开始显示插屏");
                        isShownInteractionAd = true;
                        new AdInterstitialFullManager(this, isOnceShowVip ? SZUtil.getBuyVipClass(classVip, true) : classVip)
                                .loadAdWithCallback(unitId,scenarioId);
                        SZUtil.setShownInteractionAd();
                    } else {
                        SZUtil.logError("不显示插屏");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void showInteractionAdGroMore(String unitId, OnAdClosedListener onAdClosedListener) {
        showInteractionAdGroMore(unitId,onAdClosedListener,true,null);
    }

    public void showInteractionAdGroMore(String unitId,String scenarioId, OnAdClosedListener onAdClosedListener) {
        showInteractionAdGroMore(unitId,onAdClosedListener,true,scenarioId);
    }
    public void showInteractionAdGroMore(String unitId, OnAdClosedListener onAdClosedListener,boolean isOnceShowVip,String scenarioId) {
        try {
            if(isShowAd()) {
                if (!isStop && !isShownInteractionAd) {
                    if (ADManager.getInstance().isShowGroMoreInteractionAd(SplashMinWindowManager.getInstance().isSplashShown())) {
                        SZUtil.logError("开始显示插屏");
                        isShownInteractionAd = true;
                        new AdInterstitialFullManager(this, null,isOnceShowVip&&SZUtil.isFirstShowInteractionAd()?onAdClosedListener:null)
                                .loadAdWithCallback(unitId,scenarioId);
                        SZUtil.setShownInteractionAd();
                    } else {
                        SZUtil.logError("不显示插屏");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void showInteractionAd(String codeId, Class<?> classVip) {
        showInteractionAd(codeId, classVip, true);
    }

    public void showInteractionAd(String codeId, Class<?> classVip, boolean isOnceShowVip) {
        try {
            if (isShowAd()) {
                if (!isStop && !isShownInteractionAd) {
                    if (ADManager.getInstance().isShowInteractionAd(SplashMinWindowManager.getInstance().isMinWindowShown())) {
                        SZUtil.logError("开始显示新插屏");
                        isShownInteractionAd = true;
                        new TTVideoInteractionAdLoader(getActivity(), codeId, isOnceShowVip ? SZUtil.getBuyVipClass(classVip, true) : classVip).loadAd();
                    } else {
                        SZUtil.logError("不显示新插屏");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void showInteractionAd(String codeId, OnAdClosedListener onAdClosedListener) {
        showInteractionAd(codeId, onAdClosedListener, true);
    }

    public void showInteractionAd(String codeId, OnAdClosedListener onAdClosedListener, boolean isOnceShowVip) {
        try {
            if (isShowAd()) {
                if (!isStop && !isShownInteractionAd) {
                    if (ADManager.getInstance().isShowInteractionAd(SplashMinWindowManager.getInstance().isMinWindowShown())) {
                        SZUtil.logError("开始显示新插屏");
                        isShownInteractionAd = true;
                        new TTVideoInteractionAdLoader(getActivity(), codeId, isOnceShowVip && SZUtil.isFirstShowInteractionAd() ? onAdClosedListener : null).loadAd();
                        SZUtil.setShownInteractionAd();
                    } else {
                        SZUtil.logError("不显示新插屏");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        if (isShowAd()) {
            SplashMinWindowManager.getInstance().initSplashClickEyeDataInTwoActivity(this);
        }
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onPause() {
        super.onPause();
        isStop = true;
    }

    @Override
    protected void onResume() {
        if (isShowAd()) {
            SplashMinWindowManager.getInstance().initSplashClickEyeDataInTwoActivity(this);
        }
        isStop = false;
        super.onResume();
    }

    public abstract boolean isShowAd();
}
